package com.liunian.subject.domain.handler.subject;

import com.liunian.subject.common.enums.IsDeletedFlagEnum;
import com.liunian.subject.common.enums.SubjectTypeEnum;
import com.liunian.subject.domain.entity.SubjectInfoBO;
import com.liunian.subject.domain.entity.SubjectOptionBO;
import com.liunian.subject.infra.basic.entity.SubjectBrief;
import com.liunian.subject.infra.basic.entity.SubjectJudge;
import com.liunian.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Component
public class SubjectBriefHandler implements SubjectInfoTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectTypeEnum getSubjectType() {
        return SubjectTypeEnum.BRIEF;
    }

    @Override
    public Boolean add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setAnswer(subjectBrief.getAnswer());
        subjectBrief.setCreatedAt(LocalDateTime.now());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        return subjectBriefService.save(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(long subjectId) {
        SubjectBrief subjectBrief = subjectBriefService.queryAnswerById(subjectId);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(subjectBrief.getAnswer());
        return subjectOptionBO;
    }
}
